/**
*      author: Y_Yao
*      created: 2025-01-18 19:18:45
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 1e18;
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 6;
int a[N],b[N];
int m;
vector<int> ans;
 
void solve()
{
    cin >> m;
    b[0] = 1;
    for(int i = 1;i <= 10;i++)
    {
        b[i] = b[i-1] * 3;
    }

    for(int i = 10;i >= 0;i--)
    {
        while(m >= b[i])
        {
            ans.push_back(i);
            m -= b[i];
        }
    }

    cout << ans.size() << endl;
    for(auto& e : ans)
    {
        cout << e << " ";
    }
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}